package com.mf.service.impl;

import com.mf.bo.DateScopedBo;
import com.mf.entity.Code;
import com.mf.entity.CodeHistory;
import com.mf.entity.MonthCodeHistory;
import com.mf.entity.WeekCodeHistory;
import com.mf.mapper.CodeHistoryMapper;
import com.mf.mapper.MonthCodeHistoryMapper;

import com.mf.mapper.WeekCodeHistoryMapper;
import com.mf.service.ICodeHistoryService;
import com.mf.service.IMonthCodeHistoryService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 股票历史周数据 服务实现类
 * </p>
 *
 * @author mf
 * @since 2024-06-21
 */
@Service
public class MonthCodeHistoryServiceImpl extends ServiceImpl<MonthCodeHistoryMapper, MonthCodeHistory> implements IMonthCodeHistoryService {
    @Resource
    private ICodeHistoryService codeHistoryService;

    @Resource
    private MonthCodeHistoryMapper monthCodeHistoryMapper;

    /**
     * 批量保存 添加周数据
     */
    @Override
    public void saveBatchAll(DateScopedBo dateScoped, List<Code> codeList) {
        String type = "mn";
        for (Code code : codeList) {
            final List<CodeHistory> historyList = codeHistoryService.getHistoryList(dateScoped, code.getDm(), type);
            if (historyList.isEmpty()) {
                System.out.println(code.getDm() + "没有数据=============");
                continue;
            }
            System.out.println("添加==月=="+code.getDm());
            for (CodeHistory codeHistory : historyList) {
                final MonthCodeHistory weekCodeHistory = new MonthCodeHistory();
                BeanUtils.copyProperties(codeHistory, weekCodeHistory);
                monthCodeHistoryMapper.insert(weekCodeHistory);
            }
        }
    }
}
